'use strict';

const Controller = require('egg').Controller;
class CollectController extends Controller {

  async coll() {
    const { ctx } = this;
    let res = { "code": 0, "msg": "成功" };
    const collects = ctx.request.query;
    const aaa = `INSERT INTO collects (aid,uid) VALUE (${collects.aid},${collects.uid})`;
    let results = await this.app.mysql.query(aaa);
    const bbb = `UPDATE articles SET collects=collects+1 WHERE aid=${collects.aid};`
    results = await this.app.mysql.query(bbb);
    console.log(results);
    res = results;
    console.log(results);
    ctx.body = res;

  }
  async cancel() {
    const { ctx } = this;
    let res = { "code": 0, "msg": "成功" };
    const collects = ctx.request.query;
    const aaa = ` DELETE FROM collects WHERE uid=${collects.uid} AND aid=${collects.aid};`;
    let results = await this.app.mysql.query(aaa);
    const bbb = `UPDATE articles SET collects=collects-1 WHERE aid=${collects.aid};`
    results = await this.app.mysql.query(bbb);
    console.log(results);
    res = results;

    ctx.body = res;
  }
  async collect() {
    const { ctx } = this;
    let res = { "code": 0, "msg": "成功" };
    const bb = ctx.request.query;
    const result = `SELECT * from collects where uid=${bb.uid} AND aid=${bb.aid};`
    let results = await this.app.mysql.query(result);
    console.log(33, results);
    ctx.body = results;
  }

}

module.exports = CollectController;